﻿#include <iostream>
#include <tuple>
#include <map>
int main() {
    /*这里是一个**C++17 的结构化绑定（structured bindings）
     * 和类模板参数推导（CTAD）**的完整例子，帮助你理解它们的用途和语法。*/
    std::pair<int, std::string> p = {1, "apple"};
    // 结构化绑定（C++17）
    auto [id, name] = p;
    std::cout << "ID: " << id << ", Name: " << name << std::endl;
    // 解包 tuple
    std::tuple<int, double, std::string> tup = {10, 3.14, "pi"};
    auto [i, d, s] = tup;
    std::cout << "i: " << i << ", d: " << d << ", s: " << s << std::endl;

    // 用在 map 遍历时自动解包 key 和 value
    std::map<std::string, int> fruits = {{"apple", 2}, {"banana", 3}};
    for (auto& [key, value] : fruits) {
        std::cout << key << ": " << value << std::endl;
    }

    return 0;
}
